package com.zklh.leetcode.top100;

/**
 * 回文字串算法实现
 *
 * @author 坐看落花
 * @version 1.0
 * @date 2022/3/18 10:20
 */
public class Solution647 {
    public int countSubstrings(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        int left = 0, right = 0;
        int result = 0;
        for (int i = 0; i < s.length(); i++) {
            // 分为奇数位对称 和 偶数位对称两次迭代
            for(int j =0; j < 2; j++) {
                left = i;
                right = i + j;
                while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
                    result += 1;
                    left--;
                    right++;
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
        Solution647 solution = new Solution647();
        System.out.println(solution.countSubstrings("abcba"));
    }
}
